package com.dyrj.question.controller;

import cn.hutool.core.util.RandomUtil;
import cn.hutool.core.util.StrUtil;
import cn.hutool.log.Log;
import cn.hutool.log.LogFactory;
import com.alibaba.fastjson.JSON;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.dyrj.base.system.menu.dao.SysMenuMapper;
import com.dyrj.base.system.menu.model.SysMenu;
import com.dyrj.base.system.role.dao.SysRoleMapper;
import com.dyrj.base.system.role.model.SysRole;
import com.dyrj.base.system.user.dao.SysUserMapper;
import com.dyrj.base.system.user.model.SysUser;
import com.dyrj.base.system.utils.SystemUtil;
import com.dyrj.constant.SysFrameConst;
import com.dyrj.pig.bean.TLoginLog;
import com.dyrj.pig.bean.TOrder;
import com.dyrj.pig.bean.TUser;
import com.dyrj.pig.dao.CommonMapper;
import com.dyrj.pig.dao.TLoginLogMapper;
import com.dyrj.pig.dao.TUserMapper;
import com.dyrj.pig.result.JsonResult;
import com.dyrj.question.bean.*;
import com.dyrj.question.dao.*;
import com.dyrj.question.service.*;
import com.dyrj.utils.DateUtil;
import com.dyrj.utils.SmsUtil;
import com.dyrj.utils.StringUtil;
import com.dyrj.vo.PageResultMsg;
import io.swagger.models.auth.In;
import org.apache.commons.math3.geometry.euclidean.oned.Interval;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.authc.UsernamePasswordToken;
import org.apache.shiro.subject.Subject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.math.BigDecimal;
import java.time.Period;
import java.util.*;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

@Controller
@Component
@RequestMapping("/mobile")
public class MobileController {
    private static final Log log = LogFactory.get();
    @Autowired
    private CommonMapper commonMapper;
    @Autowired
    private PDayanswerMapper pDayanswerMapper;
    @Autowired
    private TLoginLogMapper loginLogMapper;
    @Autowired
    private PIndexpicMapper pIndexpicMapper;
    @Resource
    private SysUserMapper sysUserMapper;
    @Resource
    private PTkglMapper pTkglMapper;
    @Resource
    private IPHdruleService ipHdruleService;
    @Resource
    private PHdruleMapper pHdruleMapper;
    @Resource
    private PZsnrMapper pZsnrMapper;
    @Resource
    private IPTkglService ipTkglService;
    @Resource
    private PRandquesMapper pRandquesMapper;
    @Resource
    private IPDayanswerService ipDayanswerService;
    @Resource
    private PPointruleMapper pPointruleMapper;
    @Resource
    private PPrizeruleMapper pPrizeruleMapper;
    @Resource
    private PShopingMapper pShopingMapper;
    @Resource
    private IPZslbService ipZslbService;
    @Resource
    private PDayawardMapper pDayawardMapper;
    @Resource
    private IPDayawardService ipDayawardService;
    @Resource
    private PDayexchangeMapper pDayexchangeMapper;
    @Resource
    private IPDayexchangeService ipDayexchangeService;
    @Resource
    private IPShopingService ipShopingService;
    @Resource
    private SysMenuMapper sysMenuMapper;
    @Resource
    private SysRoleMapper roleMapper;
    @Resource
    private PDwMapper pDwMapper;
    @Resource
    private IPDwService ipDwService;
    @Resource
    private PUserMapper pUserMapper;
    @Value("${string.nd}")
    private String nd;
    @GetMapping("/index")
    public String index() {
        return "mobile/index";
    }
    @GetMapping("/point")
    public String point() {
        return "mobile/point";
    }
    @GetMapping("/review")
    public String review() {
        return "mobile/review";
    }
    @GetMapping("/property")
    public String property() {
        return "mobile/property";
    }
    @GetMapping("/answer")
    public String answer() {
        return "mobile/answer";
    }
    @GetMapping("/analysis")
    public String analysis() {
        return "mobile/analysis";
    }
    @GetMapping("/answer_finish")
    public String answer_next(String uid,String dtid) {
        return "mobile/answer_finish";
    }
    @GetMapping("/prize")
    public String prize() {
        return "mobile/prize";
    }
    @GetMapping("/coupon")
    public String coupon() {
        return "mobile/coupon";
    }
    @GetMapping("/viewprize")
    public String viewprize() {
        return "mobile/viewprize";
    }

    @GetMapping("/center")
    public String center() {
        return "mobile/center";
    }
    @GetMapping("/regedit")
    public String regedit() {
        return "mobile/regedit";
    }
    @GetMapping("/moduser")
    public String moduser() {
        return "mobile/moduser";
    }
    @GetMapping("/point_rule")
    public String point_rule() {
        return "mobile/point_rule";
    }

    @GetMapping("/prize_rule")
    public String prize_rule() {
        return "mobile/prize_rule";
    }
    @GetMapping("/rank_person")
    public String rank_person() {
        return "mobile/rank_person";
    }
    @GetMapping("/rank_company")
    public String rank_company() {
        return "mobile/rank_company";
    }
    @RequestMapping("/list")
    public JsonResult<List> list(int page, int pageSize, int status, String yhbm, int type,String mobile){

        log.info("page is {}",page);
        log.info("pageSize is {}",pageSize);
        log.info("status is {}",status);
        log.info("yhbm is {}",yhbm);
        log.info("type is {}",type);

        JsonResult<List> result = new JsonResult<>();

        IPage<HashMap> listPage = commonMapper.selectPageInfo(new Page<HashMap>(page,pageSize),status,yhbm,type,mobile);

        List dataList = listPage.getRecords();

        result.setStatus(0);
        result.setInfo("success");
        result.setData(dataList);

        return result;
    }

    @RequestMapping("/orderList")
    public JsonResult<List> orderList(int page, int pageSize, String yhbm){

        log.info("page is {}",page);
        log.info("pageSize is {}",pageSize);
        log.info("yhbm is {}",yhbm);

        JsonResult<List> result = new JsonResult<>();

        IPage<HashMap> listPage = commonMapper.selectOrderList(new Page<HashMap>(page,pageSize),yhbm);

        List dataList = listPage.getRecords();

        result.setStatus(0);
        result.setInfo("success");
        result.setData(dataList);

        return result;
    }


    /**
     * 待收款列表
     * @param yhbm
     * @return
     */
    @RequestMapping("/readyCollectMoneyList")
    public JsonResult<List> readyCollectMoneyList(String yhbm){

        log.info("yhbm is {}",yhbm);

        JsonResult<List> result = new JsonResult<>();

        List dataList = commonMapper.getReadyCollectMoneyList(yhbm);

        result.setStatus(0);
        result.setInfo("success");
        result.setData(dataList);

        return result;
    }

    /**
     * 待付款列表
     * @param yhbm
     * @return
     */
    @RequestMapping("/readyPayMoneyList")
    public JsonResult<List> readyPayMoneyList(String yhbm){

        log.info("yhbm is {}",yhbm);

        JsonResult<List> result = new JsonResult<>();

        List dataList = commonMapper.getReadyPayMoneyList(yhbm);

        result.setStatus(0);
        result.setInfo("success");
        result.setData(dataList);

        return result;
    }

    @RequestMapping("/subOrderDetail")
    public JsonResult<List> subOrderDetail(String ddbm){

        log.info("ddbm is {}",ddbm);

        JsonResult<List> result = new JsonResult<>();

        List dataList = commonMapper.getSubOrderList(ddbm);

        result.setStatus(0);
        result.setInfo("success");
        result.setData(dataList);

        return result;
    }

    /**
     * 充值列表
     * @param page
     * @param pageSize
     * @param yhbm 用户编码
     * @return
     */
    @RequestMapping("/paylist")
    public JsonResult<List> paylist(int page, int pageSize,String yhbm){

        log.info("page is {}",page);
        log.info("pageSize is {}",pageSize);
        log.info("yhbm is {}",yhbm);

        JsonResult<List> result = new JsonResult<>();

        IPage<HashMap> listPage = commonMapper.selectPayPageInfo(new Page<HashMap>(page,pageSize),yhbm);

        List dataList = listPage.getRecords();

        result.setStatus(0);
        result.setInfo("success");
        result.setData(dataList);

        return result;
    }

    /**
     * 提现记录
     * @param page
     * @param pageSize
     * @param yhbm 用户编码
     * @return
     */
    @RequestMapping("/withdrawlist")
    public JsonResult<List> withdrawlist(int page, int pageSize,String yhbm){

        log.info("page is {}",page);
        log.info("pageSize is {}",pageSize);
        log.info("yhbm is {}",yhbm);

        JsonResult<List> result = new JsonResult<>();

        IPage<HashMap> listPage = commonMapper.selectWithdrawPageInfo(new Page<HashMap>(page,pageSize),yhbm);

        List dataList = listPage.getRecords();

        result.setStatus(0);
        result.setInfo("success");
        result.setData(dataList);

        return result;
    }
    @RequestMapping("/versionlist")
    public JsonResult<List> versionlist(){

        JsonResult<List> result = new JsonResult<>();

        List dataList = commonMapper.getVersionList();

        result.setStatus(0);
        result.setInfo("success");
        result.setData(dataList);

        return result;
    }

    @RequestMapping("/banklist")
    public JsonResult<List> banklist(String yhbm){

        JsonResult<List> result = new JsonResult<>();

        List dataList = commonMapper.getBankList(yhbm);

        result.setStatus(0);
        result.setInfo("success");
        result.setData(dataList);

        return result;
    }

    @RequestMapping("/tixianyhklist")
    public JsonResult<List> tiXianYhkList(String yhbm){

        JsonResult<List> result = new JsonResult<>();

        List dataList = commonMapper.getTiXianYhkList(yhbm);

        result.setStatus(0);
        result.setInfo("success");
        result.setData(dataList);

        return result;
    }

    @RequestMapping("/orderDetail")
    public JsonResult<Map> orderDetail(String ddbm){

        log.info("ddbm is {}",ddbm);

        JsonResult<Map> result = new JsonResult<>();

        List dataList = commonMapper.getOrderDetail(ddbm);
        if(dataList != null && dataList.size() > 0){
            result.setData((Map)dataList.get(0));
        }
        result.setStatus(0);
        result.setInfo("success");

        return result;
    }

    /**
     * 发送验证码
     * @param phone
     * @return
     */
    @RequestMapping("/sendValidCode")
    @ResponseBody
    public JsonResult<String> sendValidCode(HttpServletRequest request, String phone){
        HttpSession session = request.getSession();
//        SmsUtil.sendSms()
        log.info("phone is {}",phone);
        JsonResult<String> result = new JsonResult<>();
        String code = "";
        //检查手机号的有效性
        if(!isPhone(phone)){
            result.setCode(-1);
            result.setMsg("手机号无效");
            return result;
        }
        //检查手机号有效性
        SysUser sysUser = new SysUser();
        sysUser.setPhone(phone);
        SysUser user = sysUserMapper.selectByProperty(sysUser);
        if(user != null){
            code = RandomUtil.randomString("123456789",6);
            //todo  sendsms
            SmsUtil.sendYjdtSms(phone,user.getName(),code);
            user.setAccepttime(DateUtil.getDate());
            user.setMessgeno(Integer.parseInt(code));
            if(sysUser!=null) {
                sysUserMapper.updateByPrimaryKey(user);
            }else{
                sysUserMapper.insert(user);
            }
            result.setCode(0);
            result.setMsg("获取验证码成功");
            result.setData(code);
        }else{
            result.setCode(-1);
            result.setMsg("该手机号未授权，请注册！");
            result.setData("");
        }
        return result;
    }
    @RequestMapping("/sendRegeditValidCode")
    @ResponseBody
    public JsonResult<String> sendRegeditValidCode(HttpServletRequest request, String phone){
        String usrname = request.getParameter("uid");
        JsonResult<String> result = new JsonResult<>();
        String code = "";
        //检查手机号的有效性
        if(!isPhone(phone)){
            result.setCode(-1);
            result.setMsg("手机号无效");
            return result;
        }
        //检查手机号有效性
        PUser pUser = new PUser();
        pUser.setPhone(phone);
        List<PUser> list = pUserMapper.selectList(pUser);
        if(list.size()==0){
            code = RandomUtil.randomString("123456789",6);
            //todo  sendsms
            SmsUtil.sendYjdtSms(phone,usrname,code);
            pUser= new PUser();
            pUser.setPhone(phone);
            pUser.setUsrname(usrname);
            pUser.setAccepttime(DateUtil.getDate());
            pUser.setMessageno(Integer.parseInt(code));
            int r= pUserMapper.insert(pUser);
            if(r>0) {
                result.setCode(0);
                result.setMsg("获取验证码成功");
                result.setData(code);
            }else{
                result.setCode(-1);
                result.setMsg("获取验证码失败");
            }
        }else if(list.size()==1){
            code = RandomUtil.randomString("123456789",6);
            //todo  sendsms
            SmsUtil.sendYjdtSms(phone,usrname,code);
            pUser= list.get(0);
            pUser.setPhone(phone);
            pUser.setUsrname(usrname);
            pUser.setAccepttime(DateUtil.getDate());
            pUser.setMessageno(Integer.parseInt(code));
            int r= pUserMapper.updateByPrimaryKey(pUser);
            if(r>0) {
                result.setCode(0);
                result.setMsg("获取验证码成功");
                result.setData(code);
            }else{
                result.setCode(-1);
                result.setMsg("获取验证码失败");
            }
//            result.setCode(-1);
//            result.setMsg("手机号已经存在，获取验证码失败！");
        }
        return result;
    }

    /**
     * 充值、提现按钮判断
     * @param yhbm
     * @return
     */
    @RequestMapping("/bindcardcztx")
    public JsonResult<Map> sendBindCardCzTx(HttpServletRequest request, String yhbm){
//        HttpSession session = request.getSession();
        log.info("yhbm is {}",yhbm);
        JsonResult<Map> result = new JsonResult<>();
        String bindcard_tx="0";
        String bindcard_cz="0";
        Map data = new HashMap();
        //根据用户绑定银行卡信息，判断是否可以操作充值、提现按钮。
        List dataList = commonMapper.getBankList(yhbm);
        if(dataList!=null && dataList.size()>0){
            for (Object obj : dataList) {
                Map<String,Object> map_obj = (Map<String,Object>)obj;
                String yhdm = (String)map_obj.get("YHDM");
                if(yhdm!=null && !"".equals(yhdm)){
                    //充值卡
                    bindcard_cz="1";
                }else{
                    bindcard_tx="1";
                }
            }
            log.debug(JSON.toJSONString(dataList));
        }
        result.setCode(0);
        data.put("bindcard_cz",bindcard_cz);
        data.put("bindcard_tx",bindcard_tx);
        result.setData(data);
        return result;

    }
    @GetMapping("/login")
    public String login() {
        return "mobile/login";
    }
    /**
     * 手机号登录
     * @param phone
     * @return
     */
    @PostMapping("/load")
    @ResponseBody
    public JsonResult<Map> login(HttpServletRequest request, HttpServletResponse response, String phone, String code){
        JsonResult<Map> result = new JsonResult<>();
        String flag = request.getParameter("flag");
        //检查手机号有效性
        SysUser sysUser1 = new SysUser();
        sysUser1.setPhone(phone);
        if(!"check".equals(flag)) {
            sysUser1.setMessgeno(Integer.parseInt(code));
        }
        SysUser sysUser  = sysUserMapper.selectByProperty(sysUser1);
        if(sysUser!=null){
                String token = "";
                Map data = new HashMap();
                data.put("token", token);
                data.put("xm", sysUser.getName());
                data.put("dept1", sysUser.getPublicKey());
                data.put("dept2", sysUser.getPlatformPublicKey());
                data.put("phone", phone);
                data.put("id", sysUser.getId());
                result.setCode(0);
                result.setMsg("登录成功");
                Cookie cookie = new Cookie("phone", phone);
                cookie.setMaxAge(Integer.MAX_VALUE);
                response.addCookie(cookie);
                result.setData(data);
                TLoginLog loginLog = new TLoginLog();
                loginLog.setYhbm(sysUser.getName());
                loginLog.setLogintime(cn.hutool.core.date.DateUtil.formatDateTime(new Date()));
                loginLog.setYzm(code);
                loginLog.setLoginip(request.getRemoteAddr());
                loginLog.setLlqxx(request.getHeader("user-agent"));
                loginLogMapper.insert(loginLog);
                if(!"1".equals(flag)) {
                    this.authLogin();
                }
        }else{
            result.setCode(-1);
            result.setMsg("登录失败");
        }
        return result;
    }
    @PostMapping("/autoLogin")
    @ResponseBody
    public JsonResult<Map> autoLogin(HttpServletRequest request, HttpServletResponse response, String phone){
        JsonResult<Map> result = new JsonResult<>();
        String flag = request.getParameter("flag");
        //检查手机号有效性
        PUser pUser = new PUser();
        pUser.setPhone(phone);
        PUser user = pUserMapper.selectByProperty(pUser);
        SysUser sysUser = sysUserMapper.selectUserByPhone(user.getPhone());
        if(user != null&&sysUser!=null){
            String token = "";
            Map data = new HashMap();
            data.put("token", token);
            data.put("xm", sysUser.getName());
            data.put("dept1", sysUser.getPublicKey());
            data.put("dept2", sysUser.getPlatformPublicKey());
            data.put("phone", phone);
            data.put("id", sysUser.getId());
            result.setCode(0);
            result.setMsg("登录成功");
            Cookie cookie = new Cookie("phone", phone);
            cookie.setMaxAge(Integer.MAX_VALUE);
            response.addCookie(cookie);
            result.setData(data);
            TLoginLog loginLog = new TLoginLog();
            loginLog.setYhbm(sysUser.getName());
            loginLog.setLogintime(cn.hutool.core.date.DateUtil.formatDateTime(new Date()));
//            loginLog.setYzm(code);
            loginLog.setLoginip(request.getRemoteAddr());
            loginLog.setLlqxx(request.getHeader("user-agent"));
            loginLogMapper.insert(loginLog);
            this.authLogin();
        }else{
            result.setCode(-1);
            result.setMsg("登录失败");
        }
        return result;
    }
    @PostMapping("/doModUser")
    @ResponseBody
    public JsonResult<Map> doModUser(HttpServletRequest request, HttpServletResponse response){
        String id = request.getParameter("id");
        String phone = request.getParameter("phone");
        String code = request.getParameter("code");
        String name= request.getParameter("name");
        String dept3= request.getParameter("dept3");
        String dept4= request.getParameter("dept4");
        JsonResult<Map> result = new JsonResult<>();
        PUser sysUser = new PUser();
        sysUser.setPhone(phone);
        sysUser.setMessageno(Integer.parseInt(code));
        PUser exzitsysUser = pUserMapper.selectByProperty(sysUser);
        //检查手机号有效性
        SysUser exzitsysUser1 =sysUserMapper.selectByPrimaryKey(Long.valueOf(id));
        if(exzitsysUser!=null){
            if(exzitsysUser1 != null){
                exzitsysUser1.setPhone(phone);
                exzitsysUser1.setName(name);
                exzitsysUser1.setMessgeno(Integer.parseInt(code));
                exzitsysUser1.setPublicKey(dept3);
                exzitsysUser1.setPlatformPublicKey(dept4);
                int r = sysUserMapper.updateByPrimaryKey(exzitsysUser1);
                SysUser user = sysUserMapper.selectByPrimaryKey(Long.valueOf(id));
    //            if(elapsedDays<5) {
                String token = "";
                Map data = new HashMap();
                data.put("token", token);
                data.put("xm", user.getName());
                data.put("phone", phone);
                data.put("dept1", user.getPublicKey());
                data.put("dept2", user.getPlatformPublicKey());
                data.put("id", user.getId());
                if(r>0) {
                    result.setCode(0);
                    result.setMsg("修改成功");
                    result.setData(data);
                    Cookie cookie = new Cookie("phone", phone);
                    cookie.setMaxAge(Integer.MAX_VALUE);
                    response.addCookie(cookie);
                }else{
                    result.setCode(-1);
                    result.setMsg("修改失败，请稍后重试！");
                    result.setData(data);
                }
                this.authLogin();
            }else if(exzitsysUser1==null){
                result.setCode(-1);
                result.setMsg("用户不存在，请先注册！");
            }
        }else{
            result.setCode(-1);
            result.setMsg("验证码不正确！");
        }
        return result;
    }
    @PostMapping("/doRegedit")
    @ResponseBody
    public JsonResult<Map> doRegedit(HttpServletRequest request, HttpServletResponse response){
        String phone = request.getParameter("phone");
        String code = request.getParameter("code");
        String name= request.getParameter("name");
        String dept3= request.getParameter("dept3");
        String dept4= request.getParameter("dept4");
        JsonResult<Map> result = new JsonResult<>();
        //检查手机号有效性
        PUser pUser = new PUser();
        pUser.setPhone(phone);
        pUser.setMessageno(Integer.parseInt(code));
        PUser pUser1 = pUserMapper.selectByProperty(pUser);
        SysUser exzitsysUser1 =sysUserMapper.selectUserByPhone(phone);
        if(exzitsysUser1 == null){
            SysUser sysUser  = new SysUser();
            sysUser.setPhone(phone);
            sysUser.setName(name);
            sysUser.setMessgeno(Integer.parseInt(code));
            sysUser.setPublicKey(dept3);
            sysUser.setPlatformPublicKey(dept4);
            int r = sysUserMapper.insert(sysUser);
            SysUser user = sysUserMapper.selectByProperty(sysUser);
//            if(elapsedDays<5) {
            String token = "";
            Map data = new HashMap();
            data.put("token", token);
            data.put("xm", user.getName());
            data.put("phone", phone);
            data.put("dept1", user.getPublicKey());
            data.put("dept2", user.getPlatformPublicKey());
            data.put("id", user.getId());
            if(r>0) {
                result.setCode(0);
                result.setMsg("登录成功");
                result.setData(data);
                Cookie cookie = new Cookie("phone", phone);
                cookie.setMaxAge(Integer.MAX_VALUE);
                response.addCookie(cookie);
            }else{
                result.setCode(-1);
                result.setMsg("注册失败，请稍后重试！");
                result.setData(data);
            }
            TLoginLog loginLog = new TLoginLog();
            loginLog.setYhbm(user.getLoginUser());
            loginLog.setLogintime(cn.hutool.core.date.DateUtil.formatDateTime(new Date()));
            loginLog.setYzm(code);
            loginLog.setLoginip(request.getRemoteAddr());
            loginLog.setLlqxx(request.getHeader("user-agent"));
            loginLogMapper.insert(loginLog);
            this.authLogin();
        }else if(pUser1!=null&&exzitsysUser1!=null){
            result.setCode(-1);
            result.setMsg("已经注册，不用再次注册！");
        }else{
            result.setCode(-1);
            result.setMsg("注册失败");
        }
        return result;
    }

    @GetMapping("/msg")
    public String getMessage(){
        return "你已通过验证";
    }

    /**
     * 检测手机号有效性
     * @param phone
     * @return
     */
    public static boolean isPhone(String phone) {
        String regex = "^((13[0-9])|(14[5,7,9])|(15([0-3]|[5-9]))|(166)|(17[0,1,3,5,6,7,8])|(18[0-9])|(19[8|9]))\\d{8}$";
        if (phone.length() != 11) {
            return false;
        } else {
            Pattern p = Pattern.compile(regex);
            Matcher m = p.matcher(phone);
            boolean isMatch = m.matches();
            return isMatch;
        }
    }

    //我的积分
    @RequestMapping("/myPersonPoint")
    @ResponseBody
    public JsonResult<List> myPersonPoint(int page, int pageSize, String uid,String ny,String flag){
        if("".equals(uid)){
            uid=null;
        }
        JsonResult<List> result = new JsonResult<>();
        if("month".equals(flag)) {

            PDayanswer pDayanswer=new PDayanswer();
            if("".equals(ny)||ny==null||"null".equals(ny)) {
                ny =com.dyrj.utils.DateUtil.getMonth();
            }
            pDayanswer.setNy(ny);
            pDayanswer.setLimit(pageSize);
            pDayanswer.setOffset(page);
            pDayanswer.setUid(uid);
            PageResultMsg pageResultMsg = ipDayanswerService.table1(pDayanswer);
            List<PDayanswer> dataList = (List)pageResultMsg.getData();
            result.setStatus(0);
            result.setInfo("success");
            result.setData(dataList);
        }else if("year".equals(flag)) {
            IPage<HashMap> listPage = pDayanswerMapper.getPersonYearRankList(new Page<HashMap>(page, pageSize), ny, uid);
            List dataList = listPage.getRecords();
            result.setStatus(0);
            result.setInfo("success");
            result.setData(dataList);
        }
        return result;
    }
    //我的积分
    @RequestMapping("/myDeptPoint")
    @ResponseBody
    public JsonResult<List> myDeptPoint(String ny,String flag){
        JsonResult<List> result = new JsonResult<>();
        if("month".equals(flag)) {
            if("".equals(ny)||ny==null) {
                ny =DateUtil.format(DateUtil.getDate(),"yyyyMM");
            }
            PDw pDw = new PDw();
//            pDw.setLimit(pageSize);
//            pDw.setOffset(page);
            pDw.setNy(ny);
//            PageResultMsg pageResultMsg = ipDwService.table1(pDw);
            List dataList = pDwMapper.getDeptRankList(pDw);
//            List<PDw> list = (List)pageResultMsg.getData();
//            List<PDw> dataList = (List)pageResultMsg.getData();
            result.setStatus(0);
            result.setInfo("success");
            result.setData(dataList);
        }else if("year".equals(flag)) {
            List listPage = pDayanswerMapper.getDeptYearRankList(ny, null);
            result.setStatus(0);
            result.setInfo("success");
            result.setData(listPage);
        }
        return result;
    }
    //我的积分
    @RequestMapping("/getPersonDayRankList")
    @ResponseBody
    public JsonResult<List> getPersonDayRankList(String uid){
        JsonResult<List> result = new JsonResult<>();
        String rq = DateUtil.format(DateUtil.getDate(),"yyyy-MM-dd");
        List dataList= pDayanswerMapper.getPersonDayRankList(uid,rq);
        result.setStatus(0);
        result.setInfo("success");
        result.setData(dataList);
        return result;
    }
//    @RequestMapping("/getDeptRankList")
//    @ResponseBody
//    public JsonResult<List> getDeptRankList(int page, int pageSize, String uid){
//        JsonResult<List> result = new JsonResult<>();
//        String ny = DateUtil.format(DateUtil.getDate(),"yyyyMM");
//        IPage<HashMap> listPage =pDayanswerMapper.getDeptRankList(new Page<HashMap>(page,pageSize),ny,uid);
//        List dataList= listPage.getRecords();
//        result.setStatus(0);
//        result.setInfo("success");
//        result.setData(dataList);
//        return result;
//    }
    @RequestMapping("/getDayAnswerList")
    @ResponseBody
    public JsonResult<List> getDayAnswerList(int page, int pageSize, String uid,String rq){
        JsonResult<List> result = new JsonResult<>();

        PDayanswer pDayanswer=new PDayanswer();
        if(rq==null||"".equals(rq)){
            pDayanswer.setRq(null);
        }else{
            pDayanswer.setRq(DateUtil.format(DateUtil.getDate(),"yyyy-MM-dd"));
        }
        pDayanswer.setLimit(pageSize);
        pDayanswer.setOffset(page);
        pDayanswer.setUid(uid);
        PageResultMsg listPage =ipDayanswerService.table(pDayanswer);
        List<PDayanswer> dataList=(List)listPage.getData();
        List<PDayanswer> resultlist = new ArrayList();
        for(int i=0;i<dataList.size();i++) {
            PDayanswer pDayanswer1 = dataList.get(i);
            PRandques pRandques = new PRandques();
            pRandques.setDtid(pDayanswer1.getDtid());
            List<PRandques> list = pRandquesMapper.selectList(pRandques);
            pDayanswer1.setDtsl(list.size());
            int k=0;
            for(int j=0;j<list.size();j++){
                if("1".equals(list.get(j).getIscorrect())){
                    k++;
                }
            }
            pDayanswer1.setRq(DateUtil.format(pDayanswer1.getDttime(),"MM-dd HH:mm:ss"));
            pDayanswer1.setTmsl(k);
            BigDecimal point = pDayanswer1.getPoint();
            if(point==null) {
                pDayanswer1.setPoint(new BigDecimal(0));
            }
            resultlist.add(pDayanswer1);
        }
        result.setStatus(0);
        result.setInfo("success");
        result.setData(resultlist);
        return result;
    }
    @PostMapping("/addRandomQuestion")
    @ResponseBody
    public JsonResult<Map> addRandomQuestion(String uid,long dtid,int qid,String doresult,String iscorrect,String isOver){
        JsonResult<Map> result = new JsonResult<>();
        PDayanswer pDayanswer =pDayanswerMapper.selectByPrimaryKey(dtid);
//        int dtcn =  pDayanswer.getDtcn();
        if(pDayanswer.getFinishtime()==null) {
            PTkgl pTkgl = pTkglMapper.selectByPrimaryKey(qid);
            PRandques pRandques = new PRandques();
            pRandques.setLbdm(pTkgl.getLbdm());
            pRandques.setQid(qid);
            pRandques.setDtid(dtid);
            pRandques.setLbdm(pTkgl.getLbdm());
            pRandques.setLbmc(pTkgl.getLbmc());
            pRandques.setDoresult(doresult);
            pRandques.setIscorrect(iscorrect);
            PRandques searchbean = new PRandques();
            searchbean.setQid(qid);
            searchbean.setDtid(dtid);
            List<PRandques> pRandquesList = pRandquesMapper.selectList(searchbean);
            if(pRandquesList.size()==0) {
                pRandquesMapper.insert(pRandques);
            }else if(pRandquesList.size()==1) {
                pRandquesMapper.updateByPrimaryKey(pRandques);
            }

//            PRandques pRandques1 = null;
//            List<PRandques> pRandquesList1 = pRandquesMapper.selectList(searchbean);
//            if(pRandquesList1.size()>0) {
//                pRandques1=pRandquesList1.get(0);
//            }

            //当结束时，更新日答题表记录
            if ("over".equals(isOver)) {
                HashMap map = ipDayanswerService.getPointInfo(uid, Long.toString(dtid));
                BigDecimal point =  ipDayanswerService.getPoint(uid);
                String rcn =  StringUtil.parseNull(map.get("rcn"),"0");
                pDayanswer.setScore(Integer.parseInt(map.get("score") + ""));
                pDayanswer.setPoint(point.multiply(BigDecimal.valueOf(Double.parseDouble(rcn))));
                pDayanswer.setDtcn(map.get("rownum") + "");
                pDayanswer.setFinishtime(DateUtil.getDate());
                int r = pDayanswerMapper.updateByPrimaryKey(pDayanswer);
                if (r > 0) {
                    result.setCode(0);
                    result.setMsg("答题结束！");
                } else {
                    result.setCode(-1);
                    result.setMsg("答题异常！");
                }
            }
            HashMap map = new HashMap();
            map.put("dtid", dtid);
            map.put("qid", qid);
//            if(pRandques1!=null) {
//                map.put("doresult", pRandques1.getDoresult());
//            }
            result.setData(map);
        }else{
            result.setCode(-1);
//            result.setMsg("答题已经结束");
        }
        return result;
    }
    @PostMapping("/doRandomQuestion")
    @ResponseBody
    public JsonResult<Map> doRandomQuestion(String uid){
        JsonResult<Map> result = new JsonResult<>();
        SysUser sysUser = sysUserMapper.selectByPrimaryKey(Long.parseLong(uid));
        PDayanswer pDayanswer1 = new PDayanswer();
        pDayanswer1.setUid(uid);
        pDayanswer1.setKsny(DateUtil.format(DateUtil.getDate(),"yyyyMM"));
        pDayanswer1.setJsny(DateUtil.format(DateUtil.getDate(),"yyyyMM"));
        List pDayanswers = pDayanswerMapper.selectList(pDayanswer1);
        if(pDayanswers.size()<5) {
            List list = ipTkglService.getRandomList(this.nd);
            long dtid = System.currentTimeMillis();
            PDayanswer pDayanswer = new PDayanswer();
            pDayanswer.setUid(uid);
            pDayanswer.setDtid(dtid);
            pDayanswer.setUsrname(sysUser.getName());
            //        pDayanswer.setDeptid(Long.toString(sysUser.getDeptid()));
            pDayanswer.setDeptname(sysUser.getPublicKey() + StringUtil.parseNull(sysUser.getPlatformPublicKey(), ""));
            pDayanswer.setDttime(DateUtil.getDate());
            pDayanswer.setDtcn("0");
            int r = pDayanswerMapper.insert(pDayanswer);
            HashMap map = new HashMap();
            map.put("dtid", dtid);
            map.put("list", list);
            result.setData(map);
            if (r > 0) {
                result.setCode(0);
                result.setMsg("题库生成成功");
            } else {
                result.setCode(-1);
                result.setMsg("题库生成失败");
            }
        }else{
            result.setCode(-1);
//            result.setMsg("本日答题已结束，请明天再来");
            result.setMsg("每月只能答题5次，请下月再来");
        }
        return result;

    }
    @PostMapping("/getQuestionList")
    @ResponseBody
    public JsonResult<Map> getQuestionList(String dtid,String uid){
        JsonResult<Map> result = new JsonResult<>();
        List list = pDayanswerMapper.getQuestionList(dtid);
        HashMap map = new HashMap();
        map.put("dtid",dtid);
        map.put("list",list);
        result.setData(map);
        return result;
    }
    @PostMapping("/getFinishList")
    @ResponseBody
    public JsonResult<Map> getFinishList(String uid,String dtid){
        JsonResult<Map> result = new JsonResult<>();
        PDayanswer pDayanswer = pDayanswerMapper.selectByPrimaryKey(Long.parseLong(dtid));
        List list = pDayanswerMapper.getPointList(uid,dtid,"");
        HashMap map = new HashMap();
        map.put("score",pDayanswer.getScore());
        map.put("point",pDayanswer.getPoint());
        map.put("usetime",pDayanswer.getUsetime());
        if(list.size()>0){
            HashMap hashMap = (HashMap)list.get(0);
            map.put("rate",hashMap.get("rate"));
            map.put("right",hashMap.get("rcn"));
            map.put("error",hashMap.get("errorcn"));
        }
        result.setData(map);
        return result;
    }

    //积分规则
    @PostMapping("/getPointRuleList")
    @ResponseBody
    public JsonResult<Map> getPointRuleList(){
        JsonResult<Map> result = new JsonResult<>();
        List list = pPointruleMapper.selectList(null);
        HashMap map = new HashMap();
        map.put("list",list);
        result.setData(map);
        return result;
    }
    //抽奖规则
    @PostMapping("/getPrizeRuleList")
    @ResponseBody
    public JsonResult<Map> getPrizeRuleList(){
        JsonResult<Map> result = new JsonResult<>();
        List list = pPrizeruleMapper.selectList(null);
        HashMap map = new HashMap();
        map.put("list",list);
        result.setData(map);
        return result;
    }

    //抽奖规则
    @PostMapping("/getIndexPic")
    @ResponseBody
    public JsonResult<Object> getIndexPic(){
        JsonResult<Object> result = new JsonResult<>();
        PIndexpic pIndexpic = new PIndexpic();
        List<PIndexpic> list = pIndexpicMapper.selectList(pIndexpic);
        if(list.size()>0) {
            result.setData(list.get(0).getPic());
        }
        return result;
    }

    //point.html 控制器
    //获取年月日积分
    @PostMapping("/getMyPointList")
    @ResponseBody
    public JsonResult<Map> getMyPointList(String uid,String rq){
        JsonResult<Map> result = new JsonResult<>();
        if("".equals(rq)||rq==null){
            rq= DateUtil.format(DateUtil.getDate(),"yyyy-MM-dd");
        }
        String month= DateUtil.format(DateUtil.parse(rq,"yyyy-MM-dd"),"yyyyMM");
        String year= DateUtil.format(DateUtil.parse(rq,"yyyy-MM-dd"),"yyyy");
        List<HashMap> list = pDayanswerMapper.getMyPointList(uid,rq,month,year);
        HashMap map = new HashMap();
        if(list.size()>0){
            map = list.get(0);
            result.setData(map);
        }else{
            result.setData(map);
        }
        return result;
    }


    //获取年月日积分
    @PostMapping("/getPointBar")
    @ResponseBody
    public JsonResult<Map> getPointBar(String uid,String rq,int ts){
        JsonResult<Map> result = new JsonResult<>();
        if("".equals(rq)||rq==null){
            rq= DateUtil.format(DateUtil.getDate(),"yyyy-MM-dd");
        }
        List<HashMap> list = ipDayanswerService.getPointBar(uid,rq,ts);
        HashMap map = new HashMap();
        map.put("data",list);
        result.setData(map);
        return result;
    }
//    @RequestMapping("/getMyHourRankList")
//    @ResponseBody
//    public JsonResult<List> getMyHourRankList(String rq, String uid){
//        JsonResult<List> result = new JsonResult<>();
//        if("".equals(rq)||rq==null){
//            rq= DateUtil.format(DateUtil.getDate(),"yyyy-MM-dd");
//        }
//        List<HashMap> listPage =pDayanswerMapper.getMyHourRankList(rq,uid);
//        result.setStatus(0);
//        result.setInfo("success");
//        result.setData(listPage);
//        return result;
//    }
    //结束point.html 控制器
    //商城控制器
    @RequestMapping("/getCouponList")
    @ResponseBody
    public JsonResult<List> getCouponList(int pageSize, int page, String uid){
        JsonResult<List> result = new JsonResult<>();
        PShoping pShoping = new PShoping();
        pShoping.setSource("2");
        pShoping.setLimit(pageSize);
        pShoping.setOffset(page);
        PageResultMsg listPage =ipShopingService.table(pShoping);
        List<PShoping> list =(List)listPage.getData();
        result.setData(list);
        return result;
    }
    @PostMapping("/getTotalmoney")
    @ResponseBody
    public JsonResult<Map> getTotalmoney(String uid){
        JsonResult<Map> result = new JsonResult<>();
        HashMap map = new HashMap();
        BigDecimal totalmoney = ipDayawardService.getTotalAward(uid);
        map.put("totalmoney",totalmoney.doubleValue());
        result.setData(map);
        return result;
    }
    //结束商城控制器

    @GetMapping("/hdrule")
    public String hdrule() {
        return "mobile/hdrule";
    }
    @GetMapping("/hdrule_details")
    public String hdrule_details(HttpServletRequest request, ModelMap map) {

        String id=request.getParameter("id")==null?"":request.getParameter("id");
        PHdrule pHdrule = new PHdrule();
        pHdrule.setId(Integer.parseInt(id));
        List list = pHdruleMapper.selectList(pHdrule);
        map.addAttribute("list", list);
        return "mobile/hdrule_details";
    }
    //knowledge.html控制器
    @GetMapping("/knowledge")
    public String knowledge() {
        return "mobile/knowledge";
    }
    @GetMapping("/knowledge_details")
    public String knowledge_details(HttpServletRequest request, ModelMap map) {

        String lbdm=request.getParameter("lbdm")==null?"":request.getParameter("lbdm");
        PZsnr pZsnr = new PZsnr();
        pZsnr.setLbdm(lbdm);
        List list = pZsnrMapper.selectList(pZsnr);
        map.addAttribute("list", list);
        return "mobile/knowledge_details";
    }
    @PostMapping("/getZslbList")
    @ResponseBody
    public JsonResult<Map> getZslbList(){
        JsonResult<Map> result = new JsonResult<>();
        List list = ipZslbService.getZslbList("0");
        HashMap map = new HashMap();
        map.put("data",list);
        result.setData(map);
        return result;
    }
    @PostMapping("/getHdmcList")
    @ResponseBody
    public JsonResult<Map> getHdmcList(){
        JsonResult<Map> result = new JsonResult<>();
        List list = ipHdruleService.getHdmcList();
        HashMap map = new HashMap();
        map.put("data",list);
        result.setData(map);
        return result;
    }
    //结束knowledge.html控制器

    //日抽奖
    @PostMapping("/addDayAward")
    @ResponseBody
    public JsonResult<Map> addDayAward(String uid,String dtid){
        JsonResult<Map> result = new JsonResult<>();
        double money = ipDayawardService.getAward(uid);
        PDayaward pDayaward = new PDayaward();
        pDayaward.setDtid(Long.valueOf(dtid));
        List<PDayaward> plist =  pDayawardMapper.selectList(pDayaward);
        pDayaward.setAward(BigDecimal.valueOf(money));
        pDayaward.setAwardtime(DateUtil.getDate());
        pDayaward.setUid(uid);
        SysUser sysUser=  sysUserMapper.selectByPrimaryKey(Long.valueOf(uid));
        if(sysUser!=null) {
            pDayaward.setUsrname(sysUser.getName());
            pDayaward.setDeptname(sysUser.getPublicKey()+StringUtil.parseNull(sysUser.getPlatformPublicKey(),""));
        }else {
            pDayaward.setUsrname("匿名用户");
        }
        pDayaward.setBz("2021");
        if(plist.size()==0) {
            int r = pDayawardMapper.insert(pDayaward);
            if(r > 0){
                result.setCode(0);
                result.setMsg("抽奖成功");
            }else{
                result.setCode(-1);
                result.setMsg("抽奖失败");
            }
        }else{
            result.setCode(0);
            result.setMsg("已经抽奖");
        }

        HashMap map = new HashMap();
        if(plist.size()>0){
            pDayaward = plist.get(0);
            map.put("money", pDayaward.getAward());
        }else {
            map.put("money", money);
        }
        BigDecimal totalmoney = ipDayawardService.getTotalAward(uid);
        map.put("totalmoney",totalmoney);
        result.setData(map);
        return result;
    }

    @PostMapping("/getTotalAward")
    @ResponseBody
    public JsonResult<Map> getTotalAward(String uid){
        JsonResult<Map> result = new JsonResult<>();
        BigDecimal totalmoney = ipDayawardService.getTotalAward(uid);
        HashMap hashMap = new HashMap();
        hashMap.put("totalmoney",totalmoney.doubleValue());
        result.setData(hashMap);
        return result;
    }

    @RequestMapping("/getDayAwardList")
    @ResponseBody
    public JsonResult<List> getDayAwardList(int page, int pageSize, String uid){
        JsonResult<List> result = new JsonResult<>();
        PDayaward pDayaward = new PDayaward();
        pDayaward.setUid(uid);
        pDayaward.setOffset(page);
        pDayaward.setLimit(pageSize);
        PageResultMsg listPage =ipDayawardService.table(pDayaward);
        List dataList= (List)listPage.getData();
        result.setStatus(0);
        result.setInfo("success");
        result.setData(dataList);
        return result;
    }

    //抽奖
    @PostMapping("/addDayExchange")
    @ResponseBody
    public JsonResult<Map> addDayExchange(String uid,String shopid){
        JsonResult<Map> result = new JsonResult<>();
        BigDecimal totalmoney = ipDayawardService.getTotalAward(uid);
        PShoping shoping = pShopingMapper.selectByPrimaryKey(Integer.parseInt(shopid));
        PDayexchange pDayexchange = new PDayexchange();
        pDayexchange.setUid(uid);
        SysUser sysUser = sysUserMapper.selectByPrimaryKey(Long.valueOf(uid));
        if(sysUser!=null) {
            pDayexchange.setUsrname(sysUser.getName());
            pDayexchange.setDeptname(sysUser.getPublicKey()+StringUtil.parseNull(sysUser.getPlatformPublicKey(),""));
        }else{
            pDayexchange.setUsrname("匿名用户");
        }
        PShoping pShoping = pShopingMapper.selectByPrimaryKey(Integer.parseInt(shopid));
        pDayexchange.setShopid(Integer.parseInt(shopid));
        if(pShoping!=null) {
            pDayexchange.setShopname(pShoping.getSname());
            pDayexchange.setSnum(new BigDecimal(1));
            pDayexchange.setShopprice(pShoping.getPrice());
        }
        BigDecimal price = shoping.getPrice();
        BigDecimal overMoney = totalmoney.subtract(price);
        if(overMoney.doubleValue()>0) {
            int r = pDayexchangeMapper.insert(pDayexchange);
            if (r > 0) {
                result.setCode(0);
                result.setMsg("兑换成功");
            } else {
                result.setCode(-1);
                result.setMsg("兑换失败");
            }
        }else{
            result.setCode(-1);
            result.setMsg("智慧币不够！");
        }
        HashMap hashMap = new HashMap();

        hashMap.put("totalmoney",totalmoney);
        result.setData(hashMap);
        return result;
    }

    @RequestMapping("/getDayExchangeList")
    @ResponseBody
    public JsonResult<List> getDayExchangeList(int page, int pageSize, String uid){
        JsonResult<List> result = new JsonResult<>();
        PDayexchange pDayexchange = new PDayexchange();
        pDayexchange.setUid(uid);
        pDayexchange.setOffset(page);
        pDayexchange.setLimit(pageSize);
        PageResultMsg listPage =ipDayexchangeService.table(pDayexchange);
        List<PDayexchange> dataList= (List)listPage.getData();
        List<PDayexchange> retList= new ArrayList<>();
        for(int i=0;i<dataList.size();i++){
            PDayexchange pDayexchange1 = dataList.get(i);
            PShoping  pShoping = pShopingMapper.selectByPrimaryKey(pDayexchange1.getShopid());
            if(pShoping!=null) {
                pDayexchange1.setMoney(pShoping.getPrice());
                pDayexchange1.setShopname(pShoping.getSname());
            }
            retList.add(pDayexchange1);
        }

        result.setStatus(0);
        result.setInfo("success");
        result.setData(retList);
        return result;
    }

    @GetMapping("/coupon_money")
    public String coupon_money() {

//        String uid=request.getParameter("uid")==null?"":request.getParameter("uid");
//        PDayexchange pDayexchange = new PDayexchange();
//        pDayexchange.setUid(uid);
//        List list = pDayexchangeMapper.selectList(pDayexchange);
//        map.addAttribute("list", list);
        return "mobile/coupon_money";
    }
    @PostMapping("/checkPhone")
    @ResponseBody
    public JsonResult checkPhone(String phone) {
        JsonResult<Map> result = new JsonResult<>();
        SysUser sysUser = new SysUser();
        sysUser.setPhone(phone);
        SysUser user = sysUserMapper.selectByProperty(sysUser);
        if(user==null){
            result.setCode(1);
            result.setMsg("您输入的手机号未在本系统登记，请注册后登录!");
        }else{
            result.setCode(0);
            result.setMsg("手机号已经存在，请直接登录！");
        }
        return result;
    }
    @PostMapping("/checkSession")
    @ResponseBody
    public JsonResult checkSession(String phone) {
        JsonResult<Map> result = new JsonResult<>();
        Subject subject = SecurityUtils.getSubject();
        SysUser obj = (SysUser)subject.getSession().getAttribute(SysFrameConst.SYSTEM_USER);
        if(obj==null){
            result.setCode(1);
            result.setMsg("session已经过期");
        }else{
            result.setCode(-1);
//            result.setMsg("");
        }
        return result;
    }

    @GetMapping("/getDeptList")
    @ResponseBody
    public JsonResult<List> getDeptList(){
        JsonResult<List> result = new JsonResult<>();
        List sjdwlist = pDwMapper.selectSjdwmc();
        List retList = new ArrayList();
        for(int i=0;i<sjdwlist.size();i++){
            HashMap retMap = new HashMap();
            HashMap map = (HashMap) sjdwlist.get(i);
            String sjdwmc = (String)map.get("sjdwmc");
            PDw pDw = new PDw();
            pDw.setSjdwmc(sjdwmc);
            List<PDw> list = pDwMapper.selectList(pDw);
            retMap.put("sjdwmc",sjdwmc);
            retMap.put("dwmc",list);
            retList.add(retMap);
        }
//        HashMap map = new HashMap();
//        map.put("data",retList);
//        System.out.println(JSON.toJSONString(retList));
        result.setData(retList);
        return result;
    }

    public void authLogin(){
        SysUser sysUser1 = new SysUser();
        try {
            sysUser1.setAccount("admin");
            sysUser1 = sysUserMapper.selectByProperty(sysUser1);
            sysUser1.setVerify("123456");
            Subject subject = SecurityUtils.getSubject();
            // 保存用户信息进session
            subject.getSession().setAttribute(SysFrameConst.SYSTEM_USER, sysUser1);
            UsernamePasswordToken upt = new UsernamePasswordToken(sysUser1.getAccount(), sysUser1.getPassword(), false);
//            upt.
            subject.login(upt);
            // 获取权限信息
            List<SysRole> roles = roleMapper.selectRoleByUserId(sysUser1.getId());
            subject.getSession().setAttribute(SysFrameConst.SYSTEM_ROLES, roles);
            // 获取菜单列表
            // 获取权限字符串
            StringBuffer perms = new StringBuffer();
            roles.forEach(role -> {
                perms.append(role.getRoleSign());
                perms.append(",");
            });
            List<SysMenu> menus = sysMenuMapper.selectAllTreeMenu();
            menus = SystemUtil.deleteNotPermisMenu(menus, perms.toString());
            subject.getSession().setAttribute(SysFrameConst.SYSTEM_MENUS, menus);
            sysUser1.setRolesVo(roles);
            sysUser1.setMenusVo(menus);
        } catch (Exception e) {
            sysUser1 = null;
            e.printStackTrace();
        }
    }
}
